package com.acwing.partition17;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/3/25 21:46
 */
public class AC1659社交距离I {

    private static final int N = 100010, INF = 0x3f3f3f3f;
    private static char[] p = new char[N];
    private static int[] ne = new int[N];
    private static int n;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        String s = reader.readLine();
        Arrays.fill(ne, INF);
        int mind = n, last = -INF;
        for (int i = 1; i <= n; i++) {
            p[i] = s.charAt(i - 1);
            if (p[i] == '1') {
                mind = Math.min(mind, i - last);
                last = i;
            }
        }
        for (int i = n; i >= 1; i--) {
            if (p[i] == '0') {
                if (p[i + 1] == '1') ne[i] = i + 1;
                else ne[i] = ne[i + 1];
            }
        }
        int l = 1, r = mind;
        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (check(mid)) l = mid;
            else r = mid - 1;
        }
        writer.write(l + "\n");
        writer.flush();
    }

    private static boolean check(int d) {
        int cnt = 0, last = -INF;
        for (int i = 1; i <= n; i++) {
            if (p[i] == '0' && ne[i] - i >= d && i - last >= d) {
                cnt++;
                last = i;
            }
            if (p[i] == '1') last = i;
            if (cnt == 2) return true;
        }
        return false;
    }
}
